/*
 * Alberto Ruiz-Larrea Guillén...11383
 * Erdi Dogruel..................14955
 * Marcos Pérez Martín...........10324
 */

package com.example.database;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.widget.TextView;

import com.example.androball_manager.FirstMenuActivity;

//This class gets your team and players, and put them in two textviews
public class getYourTeam extends AsyncTask<OpenDB, Integer, String> {

	TextView text;
	TextView content;
	String res;
	String[] args = new String[] { "1" };
	OpenDB db;

	public getYourTeam(TextView t, TextView c, OpenDB db) {
		text = t;
		content = c;
		this.db = db;
	}

	@Override
	protected String doInBackground(OpenDB... params) {
		OpenDB db = params[0];
		SQLiteDatabase watch = db.getReadableDatabase();
		String[] columns = { OpenDB.id, OpenDB.name, OpenDB.rating,
				OpenDB.selected };
		Cursor cursor = watch.query(OpenDB.table1, columns, OpenDB.selected
				+ "=?", args, null, null, null);

		StringBuffer res = new StringBuffer("");
		cursor.moveToFirst();
		while (!cursor.isAfterLast()) {
			res.append(cursor.getString(1));
			cursor.moveToNext();
		}
		cursor.close();
		return res.toString();
	}

	@Override
	protected void onPostExecute(String result) {
		text.setText(result.toString());
		FirstMenuActivity.selected_team = result;
		getTeamPlayers watch = new getTeamPlayers(content, result.toString());
		watch.execute(db);
	}
}